<?php

class Admin_Form_CityUpdate extends Zend_Form {

    public function init() {
        
    }

    public function main($id) {
        #get db data
        $stateDb = new Admin_Model_State();
        $cityDb = new Admin_Model_City();
        $cityById = $cityDb->getCityById($id);        
        $stateArray = $stateDb->fetchAll();
        #form
        $this->setMethod("post");

        #name
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel("Enter City Name:")
                ->setRequired(true)
                ->setValue($cityById[0]['name']);

        #state select               
        $state = new Zend_Form_Element_Select('state');
        $state->setLabel("Select State:")
                ->setRequired(true);
        foreach ($stateArray as $value) {
            $state->addMultiOption($value->id, $value->name);
        }
        $state->setValue($cityById[0]['state_id']);


        #id
        $id = new Zend_Form_Element_Hidden('id');
        $id->setValue($cityById[0]['id']);

        #submit
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel("Update City")
                ->setAttribs(array('class' => 'btn btn-success'));

        #
        $this->addElements(array($name, $state, $id, $submit));
    }

}

